Nginx添加Lua模块和优化配置

您所在的位置:网站首页 Lua encodeUrl 通过配置 Nginx添加Lua模块和优化配置

Nginx添加Lua模块和优化配置

2024-07-08 19:02| 来源: 网络整理| 查看: 265

Nginx添加Lua模块和优化配置

文章目录 Nginx添加Lua模块和优化配置参考文档:一、引子二、安装LuaJIT22.1、关于 LuaJIT 和 Openresty的luajit22.2、安装2.3、环境变量配置 三、Nginx Module下载3.1、ngx_devel_kit3.2、lua-nginx-module 四、Nginx编译配置和测试4.1、nginx编译安装4.2、配置nginx4.3、启动nginx并测试 五、Nginx在reponse返回的cookie中设置HttpOnly5.1、编写脚本5.2、导入脚本 六、nginx日志切割6.1、编写日志切割脚本6.2、添加执行权限6.3、添加系统的定时任务 七、Nginx 配置 动态限制 referer八、配置限制访问点(cors)九、配置stream 模块(用于tcp和udp的转发)十、完整的配置内容如下:十一、保留180天备份文件的脚本

参考文档:

https://github.com/openresty/luajit2

https://github.com/openresty/lua-nginx-module

https://github.com/vision5/ngx_devel_kit

Nginx添加Lua模块 | Applenice

NGINX Docs | NGINX Developer Kit

https://luajit.org/

http://mirrors.sohu.com/nginx/

https://blog.csdn.net/haijiaoqihao20160106/article/details/80904756

一、引子

最近在部署项目,测试安全扫描时发现需要在 cookie 设置为 httpOnly ;虽然网上有各种做法经过测试之后发现项目不是很好;

所以最后选择了 通过 Nginx 的 Lua 脚本来进行解决,这里用来记录一下实现的过程。

二、安装LuaJIT2

为 Nginx 添加 Lua 模块的前提需要安装 LuaJIT,这里使用的是 Openresty 的 luajit2。

2.1、关于 LuaJIT 和 Openresty的luajit2

This is the official OpenResty branch of LuaJIT. It is not to be considered a fork, since we still regularly synchronize changes from the upstream LuaJIT project (https://github.com/LuaJIT/LuaJIT).

这是 LuaJIT 的官方 Openresty 分支。 它不被视为分叉,因为我们仍然定期同步来自上游 LuaJIT 项目的更改。

Additionally to synchronizing upstream changes, we introduce our own changes which haven’t been merged yet (or never will be). This document describes those changes that are specific to this branch.

除了同步上游变更之外,我们还引入了尚未合并(或永远不会合并)的自己的变更。本文档描述了那些特定于此分支的更改。

2.2、安装 $ cd /usr/local/src # 这里没有使用最新版本的,而是采用 v2.1-20201229 版本 $ wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20201229.tar.gz # 上面的地址如果下载不了,可以使用以下加速地址 $ wget https://github.91chifun.workers.dev/https://github.com//openresty/luajit2/archive/refs/tags/v2.1-20201229.tar.gz # 解压缩文件夹 $ tar -zxvf v2.1-20201229.tar.gz # 编译和安装 make PREFIX=/usr/local/luajit make install PREFIX=/usr/local/luajit

完成后看到如下内容就代表安装成功了😃

==== Successfully built LuaJIT 2.1.0-beta3 ==== ...... ==== Successfully installed LuaJIT 2.1.0-beta3 to /usr/local ==== 2.3、环境变量配置 # ======临时生效的可以执行如下脚本====== $ export LUAJIT_LIB=/usr/local/luajit/lib $ export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1 # ======永久生效的可以执行如下脚本====== $ cat >> /etc/profile /usr/local/nginx/conf/other/httponly.lua > /etc/crontab


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3